﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;
using Microsoft.Xna.Framework.Graphics;

namespace Fishes.Objects
{
    public class FishManager
    {
        #region Properties

        #endregion

        #region Public Methods

        public List<Fish> GetFish(int number, GraphicsDevice g)
        {
            List<Fish> fishes = new List<Fish>();
            string[] paths = Directory.GetFiles("fish", "*.fish");

            List<string> selectedPaths = new List<string>();
            Random r = new Random((int)DateTime.Now.Ticks);

            for (int i = 0; i < number; i++)
            {
                int n = r.Next(paths.Length);
                if (n == paths.Length)
                    n--;
                selectedPaths.Add(paths[n]);
            }

            foreach (string path in selectedPaths)
            {
                Fish fish = new Fish();
                if (!fish.Load(path, g))
                    throw new InvalidOperationException(String.Format("Failed to load fish: {0}",
                        path));

                fishes.Add(fish);
            }

            return fishes;
        }

        #endregion
    }
}
